<?php

/**
 * 
 * @author Administrator
 *
 */
class IntensifyAttrService extends Service{

    public static function indexHeader(){
        return array(
        		'id'         => array('text' => 'ID', 'rule' => 'int'),
        		'in_id'      => array('text' => '属性标识'),
        		'g_id'       => array('text' => '物品标识'), 
        		'g_name'     => array('text' => '物品名称'),
        		'quality'    => array('text' => '物品品质'),
        		'stage'      => array('text' => '物品阶数'),
        		'star'       => array('text' => '物品星级'),
        		'name_type'  => array('text' => '类型'),
        		'name'       => array('text' => '属性名称'), 
        		'level'      => array('text' => '强化等级'),
        		'attr'       => array('text' => '属性加成'),
                'action'     => array('text' => '操作')
        );
    }
    
    public static function indexData($params){
    	$modIntensifyAttr = new ModIntensifyAttr();
    	$result = $modIntensifyAttr->page($params); 
    	$dictTmp = PubDict::dict($params['g'], 'colortype');
    	$attrList = self::attrList();
    	foreach($result['data'] as &$v){ 
    		$attr ='';
    		foreach ($attrList as $key=>$val){
    			if($v[$key] != 0){
    				$attr .= $val.'：'.$v[$key].'<br/>';
    			}    			
    		}
    	    $v['attr'] = $attr;
    		$color = self::mapColor($v['quality']);
    		$v['quality'] = $dictTmp[$v['quality']];
    		
    		$v['g_name'] = '<font color="'.$color.'">'.$v['g_name'].'</font>';
    		
    		$v['action']   .= ' <a href="'.PubFunc::buildUrl('/oss/?r=intensifyAttr/delete').'&id='.$v['id'].'" confirm="是否要删除该条信息?">删除</a>';
    	}
    	unset($v);
    	return $result;
    }
    
    public static function attrList(){
    	$list = array(
    			'health_bc'          => '基础生命数值',
    			'health_ba'          => '基础生命加成',
    			'phy_attack_bc'      => '基础攻击数值',
    			'phy_attack_ba'      => '基础攻击加成',
    			'phy_defence_bc'     => '基础防御数值',
    			'phy_defence_ba'     => '基础防御加成',
    			'impale_bc'          => '基础破甲数值',    			
    			'impale_ba'          => '基础破甲加成',
    			'normal_weapon_attack_sc'      => '武器攻击数值',
    			'normal_weapon_attack_sa'      => '武器攻击加成',
    			'weapon_impale_sc'   => '武器破甲数值',
    			'weapon_impale_sa'   => '武器破甲加成',
    			'magic_weapon_attack_sc'       => '仙器攻击数值',
    			'magic_weapon_attack_sa'       => '仙器攻击加成',
    			'magic_weapon_impale_sc'       => '仙器破甲数值',
    			'magic_weapon_impale_sa'       => '仙器破甲加成',
    			'armor_health_sc'    => '防具生命数值',
    			'armor_health_sa'    => '防具生命加成',
    			'armor_defence_sc'   => '防具防御数值',
    			'armor_defence_sa'   => '防具防御加成',
    			'fight_exp_additive' => '杀怪经验加成',
    			'health_sc'          => '系统生命数值',
    			'health_sa'          => '总生命加成',
    			'phy_attack_sc'      => '系统攻击数值',
    			'phy_attack_sa'      => '总攻击加成',
    			'phy_defence_sc'     => '系统防御数值',
    			'phy_defence_sa'     => '总防御加成',
    			'impale_sc'          => '系统破甲数值',
    			'impale_sa'          => '总破甲加成',
    			'mag_attack_sc'      => '系统五行攻击',
    			'mag_attack_sa'      => '总五行攻击加成',
    			'mag_defence_sc'     => '系统五行防御',
    			'mag_defence_sa'     => '总五行防御加成',
    			'accuracy_sc'        => '系统命中数值',
    			'accuracy_sa'        => '总命中加成',
    			'dodge_sc'           => '系统闪避数值',
    			'dodge_sa'           => '总闪避加成',
    			'critical_sc'        => '系统暴击数值',
    			'critical_sa'        => '总暴击加成',
    			'resilience_sc'      => '系统韧性数值',
    			'resilience_sa'      => '总韧性加成',
    			'equip_strengthen'   => '强化基础加成',
    			'equip_basic'        => '强化基础加成',

    	);
    	return $list;
    }
    
    
    
    public static function delete($id){
    	if(empty($id)) return false;
    
    	$modIntensifyAttr = new ModIntensifyAttr();
    	$modIntensifyAttr->deleteByPk($id);
    	return true;
    }
    
    public static function upload($files){
    	$file = new PubFile();
    	$fileName = $files["file"]["name"];
    	$suffixArr = array('xls','xlsx','xlsm'); //允许上传的文件后缀
    	$check= $file::checkSuffix($fileName,$suffixArr);
    	if($check){
    		$ext = $file::getSuffix($fileName);
    		$uploadDir = '../public/upload/intensifyAttr/'.date('Ym').'/';
    		$uploadName = md5(microtime(true)).'.'.$ext;
    		$upload = $file::uploadFile($files["file"],$uploadDir,$uploadName);
    		if(!$upload){
    			return array('status' => 0, 'msg' =>$upload,'data'=>'');
    		}else{
    			$path = dirname(dirname(dirname(dirname(__File__)))).'/public/upload/intensifyAttr/'.date('Ym').'/'.$uploadName;  //获取绝对路径
    			return array('status' => 1, 'msg' =>'上传成功','data'=>$path);
    		}
    	}else{
    		return array('status' => 0, 'msg' =>'上传文件后缀不允许!','data'=>'');
    	}
    }
    
    public static function xlsAdd($data){
    	$modIntensifyAttr = new ModIntensifyAttr();
    	unset($data[1]);
    	unset($data[2]);
    	unset($data[3]);
    	unset($data[4]);
    	
    	$add_data = array();
    	$gid_array = $modIntensifyAttr->getGid();
    	
    	$gid_in = array();
    	foreach ($gid_array as $key=>$val){
    		$gid_in[] = $val['f_id'];
    	}
    	$game = PubBase::getCurrentGame();
        $all_num = count($data);
        $success_num = 0;
        $error_num = 0;
    	foreach($data as $v){
    		if(in_array($v['A'], $gid_in)){  //已经存在
    			$error_num++;
    			continue;
    		}
    		$d = array();
    		$d['game'] = $game;
    		$d['in_id'] = $v['A'];
    		$d['g_id'] = $v['B'];
    		$d['name_type'] = $v['C'];
    		$d['name'] = $v['D'];
    		$d['level'] = $v['E'];
    		$d['intensify_material'] = $v['F'];
    		$d['decompose_material'] = $v['G'];
    		$d['health_bc'] = $v['H'];
    		$d['health_ba'] = $v['I'];
    		$d['phy_attack_bc'] = $v['J'];
    		$d['phy_attack_ba'] = $v['K'];
    		$d['phy_defence_bc'] = $v['L'];
    		$d['phy_defence_ba'] = $v['M'];
    		$d['impale_bc'] = $v['N'];
    		$d['impale_ba'] = $v['O'];
    		$d['normal_weapon_attack_sc'] = $v['P'];
    		$d['normal_weapon_attack_sa'] = $v['Q'];
    		$d['weapon_impale_sc'] = $v['R'];
    		$d['weapon_impale_sa'] = $v['S'];
    		$d['magic_weapon_attack_sc'] = $v['T'];
    		$d['magic_weapon_attack_sa'] = $v['U'];
    		$d['magic_weapon_impale_sc'] = $v['V'];
    		$d['magic_weapon_impale_sa'] = $v['W'];
    		$d['armor_health_sc'] = $v['X'];
    		$d['armor_health_sa'] = $v['Y'];
    		$d['armor_defence_sc'] = $v['Z'];
    		$d['armor_defence_sa'] = $v['AA'];
    		$d['fight_exp_additive'] = $v['AB'];
    		$d['health_sc'] = $v['AC'];
    		$d['health_sa'] = $v['AD'];
    		$d['phy_attack_sc'] = $v['AE'];
    		$d['phy_attack_sa'] = $v['AF'];
    		$d['phy_defence_sc'] = $v['AG'];
    		$d['phy_defence_sa'] = $v['AH'];
    		$d['impale_sc'] = $v['AI'];
    		$d['impale_sa'] = $v['AJ'];
    		$d['mag_attack_sc'] = $v['AK'];
    		$d['mag_attack_sa'] = $v['AL'];
    		$d['mag_defence_sc'] = $v['AM'];
    		$d['mag_defence_sa'] = $v['AN'];
    		$d['accuracy_sc'] = $v['AO'];
    		$d['accuracy_sa'] = $v['AP'];
    		$d['dodge_sc'] = $v['AQ'];
    		$d['dodge_sa'] = $v['AR'];
    		$d['critical_sc'] = $v['AS'];
    		$d['critical_sa'] = $v['AT'];
    		$d['resilience_sc'] = $v['AU'];
    		$d['resilience_sa'] = $v['AV'];
    		$d['equip_strengthen'] = $v['AW'];
    		$d['equip_basic'] = $v['AX'];
    		array_push($add_data, $d);
    	}
    	$success_num = $all_num - $error_num;
    	$msg = '导入成功 '.$success_num.' 条，失败 '.$error_num.' 条';
    	$result = $modIntensifyAttr->addmuch($add_data);
    	return array('status' => 1, 'msg' =>$msg,'data'=>'');
    }
    
    

    
}